#@layoutT("录制分发")
#define css()
<style type="text/css">
.div-scroll{
	overflow:auto;
	border-top:1px solid #DCDCDC;
	border-left:1px solid #DCDCDC;
	border-bottom:1px solid #DCDCDC;
	min-width:345px;
	position: relative;
}
  .l-layout-header {
    position: relative;
    padding-left: 10px;
    color: #183152;
    font-weight: bold;
    height: 30px;
    line-height: 30px;
    background: #fff;
    border-bottom: 1px solid #eee;
    overflow: hidden;
    cursor: pointer;
}
.layui-form-item .layui-inline {
    /* margin-bottom: 5px; */
    margin-right: 0px;
}
.f-form .layui-inline {
    margin-top: 3px;
    margin-bottom: 0px;
}
#container{
   background: #ffffff;
}
.search-model {
    margin-bottom: 0px;
    padding: 0px;
}
.layui-container-fluid{
 background: #ffffff;
}
</style>
#end
#define main()
		<div class="layui-row layui-col-space1 task-row">
		  <div class="layui-col-xs12 div-scroll">
			 <div class="l-layout-header"><span class="header-span">#(roleName)</span> 可选用户</div>
             <div class="l-scroll"style="left: 0px;top: 0px;">
            	#@formStart()
					<div class="layui-inline">
					   	<input type="search" name="userName" autocomplete="off" class="layui-input" placeholder="姓名"/>
					</div>
				#@formEnd()

           		<table id="maingrid" lay-filter="maingrid"></table>
             </div>
		</div>
	</div>

	<script type="text/html" id="toolbar">
		<div class="layui-btn-container">
			<button class="layui-btn layui-btn-sm" lay-event="getCheckData">一键分发</button>
		</div>
	</script>

	<!-- 	每行的操作按钮 -->
	<script type="text/html" id="bar_maingrid">
  	    <a class="layui-btn layui-btn-xs" lay-event="add">选择</a>
	</script>

#end

#define js()
<!-- 分页表格 -->
<script>
    var userCodes = "";
	var groupIds="#(groupIds)";
	//选择用户
	function addUser(obj){
		var data=obj.data;
		var userCode=data.user_code;
		var url="#(path)/user/upload/file/saveDestribute?userCodes="+userCode+"&groupIds="+groupIds;
		$.ajax({
			url
			,type:"POST"
			,success:function(data){				
				$(".layui-laypage-btn").click();
				if(num==0){
					queryRoleUserList();
				}				
				layer.msg(data.msg);
			}
		});
	}

	var num=0;
	//查询角色用户,是否重新渲染表格
	function queryRoleUserList() {
		var url="#(path)/portal/core/sysUser/list";
		$.ajax({
			 url
			 ,type:"POST"
			 ,success:function(data){
				 num=data.totalRow;
				 if(data.totalRow<=1){					
					table.reload('maingrid', {});
				 }
			}
		});
	}

	//未选用户列表
	gridArgs.title='用户';
	gridArgs.dataId='id';
	gridArgs.gridDivId ='maingrid';
	gridArgs.heightDiff =80;
	initGrid({id : 'maingrid'
			,elem : '#maingrid'
			,cellMinWidth: 160
			,cols : [ [
					{title: '主键',field : 'id',width : 35,checkbox : true},						
					{title: '用户名', field: 'user_code',sort:true},
        			{title: '姓名', field: 'user_name',sort:true},
	        		{title: '所属部门', field: 'org_name',sort:true},																	
					{title: '操作',fixed:'right',width : 100,align : 'left',toolbar : '#bar_maingrid'} // 这里的toolbar值是模板元素的选择器
			] ]
			,url:"#(path)/portal/core/sysUser/list"
		    , toolbar: '#toolbar' //开启头部工具栏，并为其绑定左侧模板
			,searchForm : 'searchForm'
	},{add:addUser});


	layui.use(['form', 'table'], function () {
		var $ = layui.$
				, layer = layui.layer
				, form = layui.form
				, table = layui.table;

		//头工具栏事件
		table.on('toolbar(maingrid)', function (obj) {
			var checkStatus = table.checkStatus(obj.config.id);
			var data = checkStatus.data;
			userCodes="";
			data.forEach((item, index, array) => {
				userCodes += item.id + ","
			});
			userCodes = userCodes.substr(0, userCodes.length - 1);
			$.ajax({
				url:"#(path)/user/upload/file/saveDestribute",
				data:{
					"userCodes":userCodes,
					"groupIds":groupIds
				},
				type:"post",
				success:function(data){
					table.reload('maingrid', {});
				    layer.msg(data.msg);
				}
			});
		});
	});

</script>
#end

  